<template>
	<view class="material" @click="toDetail(props.task)">
		<image
			v-if="props.task.is_join"
			class="yjd"
			src="https://movieface.oss-cn-hangzhou.aliyuncs.com/icon/wx/is_get_order.png"
			mode="scaleToFill"
		/>

		<!-- <image v-else-if="!props.task.is_get" class="yjd" src="" mode="scaleToFill" /> -->

		<view class="row1">
			<image class="main-img" :src="parseImage" mode="aspectFill"></image>

			<view class="content">
				<view class="title line2">
					{{ props.task.title }}
				</view>

				<view class="title">
					<text class="tag" v-if="props.task.is_comment">{{ appTxtStore.appTxt.tags.comment[1] }}</text>
					<text class="tag" v-if="props.task.is_real_goods == 1">
						{{ appTxtStore.appTxt.tags.real_goods[1] }}
					</text>
					<text class="tag" v-if="props.task.is_real_goods == 0">
						{{ appTxtStore.appTxt.tags.real_goods[0] }}
					</text>
				</view>

				<wd-progress :percentage="computedProgress" custom-class="progress-line" color="#e63e2e" hide-text />

				<view class="progress">
					<view class="progress-item">
						<text>{{ props.task.surplus_num }}</text>
						<text>剩余</text>
					</view>

					<view class="progress-item">
						<text>{{ props.task.total_num }}</text>
						<text>总数</text>
					</view>
				</view>
			</view>
		</view>

		<view class="row">
			<text>
				<text style="color: #666; font-size: 24rpx">
					{{ appTxtStore.appTxt.index.task_reward.name }}
				</text>
				{{ appTxtStore?.appTxt?.unit }}{{ props.task.unit_price }}
			</text>
			<view class="btn" v-if="props.task.is_get" @click.stop="toDetail(props.task)">
				{{ appTxtStore.appTxt.index.buttons.create_order.name }}
			</view>
		</view>
	</view>
</template>
<script setup>
import { useAppTxtStore } from '@/store/appTxt'

const props = defineProps({
	task: { type: Object },
})

const appTxtStore = useAppTxtStore()

const parseImage = computed(() => {
	if (props.task.goods_image) {
		return props.task.goods_image_url
	} else {
		return `https://movieface.oss-cn-hangzhou.aliyuncs.com/icon/wx/default_goods.png`
	}
})

const toDetail = (task) => {
	console.log('%c [ task ]-77', 'font-size:13px; background:pink; color:#bf2c9f;', task)
	if (!task.is_get && task.not_get_msg != '您已接过该类型任务') {
		uni.showToast({
			title: task.not_get_msg,
			icon: 'none',
			mask: true,
		})

		return
	}

	uni.navigateTo({ url: '/pages/task/index?id=' + task.id })
}

const computedProgress = computed(() => Number((Number(props.task.surplus_num) / Number(props.task.total_num)) * 100))
</script>
<style lang="scss" scoped>
:deep(.wd-progress__outer) {
	height: 20rpx;
	border-radius: 10rpx;
}

.material {
	width: 710rpx;
	min-height: 260rpx;
	background-color: #fff;

	box-sizing: border-box;
	padding: 24rpx;
	gap: 12rpx;

	display: flex;
	flex-flow: column nowrap;
	justify-content: flex-start;

	position: relative;

	.yjd {
		position: absolute;
		top: 20rpx;
		right: 20rpx;
		width: 100rpx;
		height: 100rpx;
	}

	.row1 {
		width: 100%;
		display: flex;
		flex-flow: row nowrap;
		justify-content: flex-start;
	}

	.main-img {
		width: 200rpx;
		height: 200rpx;
		border-radius: 10rpx;
		// background-color: #f2f2f2;
	}

	.divider {
		width: 710rpx;
		margin: 0;
		padding: 0;
	}

	.content {
		flex: 1;
		border-radius: 10rpx;

		min-height: 200rpx;
		box-sizing: border-box;
		padding-left: 20rpx;
		gap: 12rpx;

		display: flex;
		flex-flow: column nowrap;
		justify-content: space-between;
		align-items: flex-start;

		.title {
			font-weight: bold;
			font-size: 30rpx;
			color: #333333;
			line-height: 40rpx;
			min-height: 40rpx;

			.tag {
				color: #e63e2e;
				font-size: 20rpx;
				line-height: 28rpx;
				border: 2rpx solid #e63e2e;
				box-sizing: border-box;
				padding: 3rpx;
				margin-right: 6rpx;
				border-radius: 3rpx;
			}
		}

		.progress {
			width: 100%;
			display: flex;
			flex-flow: row nowrap;
			justify-content: space-between;

			font-size: 24rpx;

			.progress-item {
				height: 60rpx;

				display: flex;
				flex-flow: column nowrap;
				justify-content: space-between;
				align-items: center;

				text:last-child {
					color: #999;
					font-size: 20rpx;
				}
			}
		}
	}

	.row {
		width: 100%;
		padding-top: 6rpx;

		display: flex;
		flex-flow: row nowrap;
		justify-content: space-between;
		align-items: center;
		box-sizing: border-box;

		gap: 24rpx;

		font-family: PingFang SC;
		font-weight: 800;
		font-size: 36rpx;
		color: #e63e2e;
		line-height: 36rpx;

		.has-get {
			border: 1rpx solid #e63e2e;
			background-color: #fff;
			color: #e63e2e;

			text-align: center;
			padding: 0 24rpx;
			height: 50rpx;
			line-height: 50rpx;
		}

		.btn {
			border: 1rpx solid #414141;
			background-color: #e63e2e;
			color: #fff;
			text-align: center;
			padding: 0 24rpx;
			height: 60rpx;
			line-height: 60rpx;
			border-radius: 30rpx;
		}
	}
}
</style>
